﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace DatabaseHelper
{
    public class DAL
    {
        #region Public Properties
        public static string ConnectionString {get; set;}
        #endregion

        #region Constratuctor
        /// <summary>
        ///  Initializes a new instance of the class.
        /// </summary>
        public DAL()
        {
        }
        #endregion

        #region Public Static Method
        public static DataSet FillDataSet(string query)
        {
            DataSet ds = new DataSet();
            
            try
            {
                using (SqlConnection connection = new SqlConnection(ConnectionString))
                {
                    if (connection.State != ConnectionState.Open)
                    {
                        connection.Open();
                    }
                    using (SqlCommand cmd = new SqlCommand(query, connection))
                    {
                        cmd.CommandType = CommandType.Text;

                        using (SqlDataAdapter dataAdapter = new SqlDataAdapter(cmd))
                        {
                            dataAdapter.Fill(ds);
                        }
                    }
                    connection.Close();
                }

            }
            catch (Exception ex)
            {
                throw new Exception("Failed to Fill Data", ex);
            }
            return ds;
        }
        #endregion


    }
}
